package com.ccc.boot.generator.service;

import com.ccc.boot.generator.dto.TableDTO;
import com.ccc.boot.generator.mapper.TableMapper;
import com.ccc.boot.generator.response.TableResultResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 获取table 业务层
 *
 * @author superC
 * @date 2022/3/29
 * @version 0.1.0
 */

@Service
public class TableService {

    @Autowired
    private TableMapper tableMapper;

    /**
     * 获取列表数据
     * @param params
     * @return
     */
    public TableResultResponse<TableDTO> queryList(Map<String, Object> params) {
        int page = Integer.parseInt(params.get("page").toString());
        int limit = Integer.parseInt(params.get("limit").toString());
        int offset = (page-1) * limit;
        params.put("offset", offset);
        params.put("limit", limit);
        int total = tableMapper.queryTotal(params);
        List<TableDTO> list = tableMapper.queryList(params);

        return new TableResultResponse<TableDTO>(total, list);
    }

}
